package lesson16;

class Person 
{
	private static int personId = 1;
	static String courseName = "JAVAEE";
	public String name;
	final String address = "Sofia, ...";
	private int age;
	private String password;//set in constructor
	//make method changePassword(String olePass, String newPass, String newPass2)
	private final String egn;
	
	City c = new City();
		
	public Person(String egn, String password)
	{
		name = "Ivan";
		age = 0;
		this.egn = egn;
		this.password = password;
		c.addPerson(this, personId++);
	}
	
	static int getPensionAge()
	{
		return 65;
	}
	
	static int calcWorkingYearsLeft(int currentAge)
	{
		return getPensionAge()-currentAge;
	}
	
	void setAge(int age)
	{
		if(age >=0 && age < 200)
			this.age = age;
	}
	
	int getAge(String password)
	{
		if(this.password.equals(password))
			return age;
		else
			return -1;
	}
	
	public boolean validateAge()
	{
		getAge(password);
		return age > 0;
	}
	
	void changeCity(final City newCity)
	{
		newCity.name = "Sofia";
		c = newCity;
	}
	
	public void changePassword(String oldPass, String newPass, String newPass2)
	{
		if(newPass.equals(newPass2))
		{
			if(this.password.equals(oldPass))
				this.password = newPass;
			else
				System.out.println("Old password missmatch. Please try again!");
		}
		else
			System.out.println("New password missmatch!");
	}
	
	
}
